﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Description;
using System.Text;
using RrslLite.Net.Contracts;
using RrslLite.Net.Messages;

namespace RrslLite.Host
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class WcfDuplexMessageService : MessageService, IWcfDuplexMessageService
    {
        public virtual void InvokeOperations(params Message[] messages)
        {
            IWcfDuplexMessageClient client = GetDuplexCallbackChannel();

            var result = ProcessMessages(messages);

            client.BeginReceive(result.ToArray()
                , (i) => { var some = client; }
                , null);
        }

        protected virtual IWcfDuplexMessageClient GetDuplexCallbackChannel()
        {
            return OperationContext.Current.GetCallbackChannel<IWcfDuplexMessageClient>();
        }
    }
}
    